#define BOOST_TEST_MODULE lambda_visitor test
#include <boost/test/unit_test.hpp>

#include "lambda_visitor.hpp"

#include <list>
#include <algorithm>
#include <boost/variant.hpp>


BOOST_AUTO_TEST_CASE( test_single_lambda )
{
    int index = 0;
    int numbers[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

    auto visitor = util::make_lambda_visitor([&](int const& num) {
            BOOST_CHECK_EQUAL(&num, numbers + index++);
        });

    std::for_each(numbers, numbers + sizeof(numbers), visitor);
    BOOST_CHECK_EQUAL(sizeof(numbers), index);
}

BOOST_AUTO_TEST_CASE( test_3_lambdas )
{

    int i = 1;
    bool b = true;
    std::string str("a");
    typedef boost::variant<int, bool, std::string> variant;
    std::list<variant> list;
    list.push_back(i);
    list.push_back(b);
    list.push_back(str);
    int callCounter = 0;

    auto visitor = util::make_lambda_visitor(
        [&] (int & num) {
            BOOST_CHECK_EQUAL(i, num);
            callCounter++;
        },
        [&] (bool val) {
            BOOST_CHECK_EQUAL(b, val);
            callCounter++;
        },
        [&] (std::string s) {
            BOOST_CHECK_EQUAL(str, s);
            callCounter++;
        });

    std::for_each(list.begin(), list.end(), boost::apply_visitor(visitor));
    BOOST_CHECK_EQUAL(list.size(), callCounter);
}

